<!DOCTYPE html>
<html>
<head>
    <title>历史</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <#--样式-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/css/style.css">
    <#--layui-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/layui/css/layui.css">

</head>
<body >





    <div class="content" >



       <div >
           <#--月亮放置区-->
           <div class="light" style="cursor:pointer;" onclick="window.location.href = '/history/'">
           </div>

           <hr class="line-left">
           <hr class="line-right">

           <div class="main">
               <h1 class="title">更新地点映射</h1>
           </div>




           <div class="textContent" style="padding-bottom: 300px;">

               <div style="width: 900px;">

                   <form class="layui-form layui-form-item" id="formLand">
                       <input type="hidden" name="id" value="${land.id!''}"/>


                       <div class="layui-inline">
                           <label class="layui-form-label">开始时间</label>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.startYear!''}"  lay-verify="checkNumber" type="number" name="startYear" placeholder="年" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid">-</div>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.startMonth!''}" lay-verify="checkMonth|checkNumber" type="number" max="12" min="1" name="startMonth" placeholder="月" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid">-</div>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.startDay!''}" lay-verify="checkDay|checkNumber" type="number" max="31" min="1" name="startDay" placeholder="日" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid layui-word-aux">古时启用该地名时间</div>
                       </div>
                       <br/>
                       <br/>

                       <div class="layui-inline">
                           <label class="layui-form-label">结束时间</label>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.endYear!''}" lay-verify="checkNumber" type="number" name="endYear" placeholder="年" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid">-</div>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.endMonth!''}" lay-verify="checkMonth|checkNumber" type="number" max="12" min="1" name="endMonth" placeholder="月" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid">-</div>
                           <div class="layui-input-inline" style="width: 100px;">
                               <input value="${land.endDay!''}" lay-verify="checkDay|checkNumber" type="number" max="31" min="1" name="endDay" placeholder="日" autocomplete="off" class="layui-input">
                           </div>
                           <div class="layui-form-mid layui-word-aux">古时结束使用该地名时间</div>
                       </div>
                       <br/>
                       <br/>


                       <div class="layui-form-item">
                           <label class="layui-form-label">古代地名</label>
                           <div class="layui-input-block">
                               <input value="${land.name!''}" required lay-verify="required" type="text" name="name" lay-verify="title" autocomplete="off" placeholder="古代地名，必填" class="layui-input">
                           </div>
                       </div>

                       <div class="layui-form-item">
                           <label class="layui-form-label">现代地名</label>
                           <div class="layui-input-block">
                               <input value="${land.nowName!''}" required lay-verify="required" type="text" name="nowName" lay-verify="title" autocomplete="off" placeholder="现代地名，必填" class="layui-input">
                           </div>
                       </div>

                       <div class="layui-form-item layui-form-text">
                           <label class="layui-form-label">备注</label>
                           <div class="layui-input-block">
                               <textarea placeholder="" name="bz" class="layui-textarea">${land.bz!''}</textarea>
                           </div>
                       </div>


                       <br/>
                       <br/>


                       <div class="layui-form-item">
                           <div class="layui-input-block">
                               <button class="layui-btn" lay-submit lay-filter="updLand" >更新</button>
                               <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                           </div>
                       </div>

                   </form>

               </div>




           </div>



       </div>
    </div>




</body>


<!-- scripts -->

<#--layui-->
<script src="${request.contextPath}/layui/layui.js"></script>
<#--js-->
<script src="${request.contextPath}/js/jquery.min.js"></script>


<script>


    // 引入弹出层
    var form = null;
    layui.use('form', function(){
        form = layui.form;

        /**
         * 监听提交,新增地点映射
         */
        form.on('submit(updLand)', function(data){
            $.ajax({
                url:'/history/other/updLand', //请求的url地址
                dataType:'json', //返回的格式
                data: $("#formLand").serialize(),//参数值 {"id":"value"}
                type:'post', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + JSON.stringify(data.field))
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);
                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }
            });

            //返回false则不会重置
            return false;
        });

        form.verify({
            //自定义月份检查
            checkMonth: function(value, item){
                if (!isInteger){
                    return "只能是数字";
                }
                if (value == null || value === ""){
                    return;
                }
                if (value < 1 || value > 12 ){
                    return "月份不合法";
                }
            },
            checkDay:function (value, item) {
                if (!isInteger){
                    return "只能是数字";
                }
                if (value == null || value === ""){
                    return;
                }
                if (value < 1 || value > 31 ){
                    return "日期不合法";
                }
            },
            checkNumber:function (value, item) {
                if (value == null || value === ""){
                    return;
                }
                if (!isInteger){
                    return "只能是数字";
                }
            }

        });
    });


    /**
     * 判断是否整数
     * @param obj
     * @returns {boolean} 是整数，则返回true，否则返回false
     */
    function isInteger(obj) {
        return  Math.round(obj) === obj
    }


</script>



</html>